<?
if (!defined('_GNUBOARD_')) exit;

// 방문자수 출력
function popup()
{
    global $config, $g4;

	$POPUP_ID = get_cookie("POPUP_ID");

	$POP_QUERY = "select * from $g4[popup_table] where pop_use='YES' order by idx asc";
	$POP_RESULT = mysql_query($POP_QUERY);

ob_start();

$POPUP_CNT = 0;
while($POP_DATA = mysql_fetch_array($POP_RESULT))
	{
		if(!eregi($POP_DATA[pop_code],$POPUP_ID))
		{
?>
<DIV id="POP_<?=$POP_DATA[pop_code]?>" style="display:inline;position:absolute;left:<?=$POP_DATA[pop_left]?>px;top:<?=$POP_DATA[pop_top]?>px;width:<?=$POP_DATA[pop_width]?>px;height:<?=$POP_DATA[pop_height]+12?>px;background:#FFFFFF;border:solid 1px #CCCCCC">
<table cellpadding="0" cellspacing="0" border="0" width="<?=$POP_DATA[pop_width]?>" height="<?=$POP_DATA[pop_height]?>">
<tr>
<td align="left" valign="top"><?=stripslashes($POP_DATA[pop_content])?></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="<?=$POP_DATA[pop_width]?>">
<tr>
<td align="right"><label for="toDayClose_<?=$POP_DATA[pop_code]?>"><input id="toDayClose_<?=$POP_DATA[pop_code]?>" type="checkbox" onclick="POP_CLOSE_SEND('<?=$POP_DATA[pop_code]?>')">오늘하루 창 닫기</label><span style="cursor:pointer" onclick="POP_CLOSE2('<?=$POP_DATA[pop_code]?>')">&nbsp;&nbsp;<span style="background:#888888;width:12px;text-align:center;height:10px;color:#FFFFFF;font-size:11px;margin-bottom:2px" align="absmiddle">x</span>닫기</span>&nbsp;</td>
</tr>
</table>
</DIV>
<?
			$POPUP_CNT++;
		}
	}
if($POPUP_CNT > 0)
{
?>
<script>
var ajax = function(url,callback){ 
	this.xmlHttp = this.createHttpRequest(); 
	if(!this.check_made_xmlHttp()){return false;} 
	this.sendRequest(url,callback); 
} 

ajax.prototype.createHttpRequest= function(){ 
	if(window.ActiveXObject){ 
		try { 
			return new ActiveXObject("Msxml2.XMLHTTP") ; 
		} catch (e) { 
			try { 
				return new ActiveXObject("Microsoft.XMLHTTP") ; 
			} catch (e2) { 
				return null ; 
			} 
		} 
	}
	else if(window.XMLHttpRequest){ 
		 return new XMLHttpRequest() ; 
	}
	else { 
		return null ; 
	} 
}

ajax.prototype.sendRequest= function(url,callback){ 
	var xmlHttp = this.xmlHttp; 
	var connect_page_try=0;

	try {
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	catch(e) {
		connect_page_try++;
		if(connect_page_try<3) {
			alert('서버와의 통신에 실패하였습니다. 재시도 합니다. try : #' + connect_page_try);			
		}
		else {
			alert('서버와의 통신에 실패하였습니다.');
			//location.href="/";
			return false;
		}
	}

    xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4&&xmlHttp.status == 200) {
			callback(xmlHttp);
		}
	}
}

ajax.prototype.check_made_xmlHttp= function(){ 
	if(!this.xmlHttp) return false; 
	else return true; 
}

ajax.prototype.debug= function(){ 
	alert(this.xmlHttp.responseText);
}

function POP_CLOSE_SEND(POP_ID)
{
	new ajax("<?=$g4[path]?>/lib/popup_close.php?POP_ID="+POP_ID,POP_CLOSE);
}
function POP_CLOSE(Result)
{
	var POP_ID=Result.responseText;
	document.all("POP_"+POP_ID).style.display="none";
}
function POP_CLOSE2(POP_ID)
{
	document.all("POP_"+POP_ID).style.display="none";
}
</script>
<?
}
$POPUP = ob_get_contents();
ob_end_clean();

    return $POPUP;
}
?>